import sqlite3

conn = sqlite3.connect('/home/gd/dispatch-system/backend/instance/dispatch_system.db')
cursor = conn.cursor()

# 检查权限表
cursor.execute('SELECT id, name, code, is_active FROM permissions WHERE code IN ("work_order.view", "material.view")')
print('Permissions:')
rows = cursor.fetchall()
for row in rows:
    print(f"ID: {row[0]}, Name: {row[1]}, Code: {row[2]}, Active: {row[3]}")

# 检查worker角色的权限
cursor.execute('SELECT rp.role, rp.permission_id, p.code FROM role_permissions rp JOIN permissions p ON rp.permission_id = p.id WHERE rp.role = "worker" AND p.code IN ("work_order.view", "material.view")')
print('\nRole permissions for worker:')
rows = cursor.fetchall()
for row in rows:
    print(f"Role: {row[0]}, Permission ID: {row[1]}, Code: {row[2]}")

# 检查用户ID为3的特殊权限
cursor.execute('SELECT up.user_id, up.permission_id, p.code FROM user_permissions up JOIN permissions p ON up.permission_id = p.id WHERE up.user_id = 3')
print('\nUser permissions for user_id 3:')
rows = cursor.fetchall()
for row in rows:
    print(f"User ID: {row[0]}, Permission ID: {row[1]}, Code: {row[2]}")

# 检查is_active字段的值类型
cursor.execute('SELECT code, is_active, typeof(is_active) FROM permissions WHERE code IN ("work_order.view", "material.view")')
print('\nPermissions is_active field types:')
rows = cursor.fetchall()
for row in rows:
    print(f"Code: {row[0]}, is_active: {row[1]}, Type: {row[2]}")

conn.close()